package com.example.hosptialtag.controller;

import com.example.hosptialtag.pojo.Tag;
import com.example.hosptialtag.service.BindService;
import com.example.hosptialtag.service.PatientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.Arrays;
import java.util.List;

/**
 * @Author liuyuhao&caiang
 * @Date 2022/2/21
 */

@Controller
public class PatientController {
    @Autowired
    private PatientService patientService;
    @Autowired
    private BindService bindService;

    @RequestMapping(value = "/patientDetailPage")//前往绑定页面
    public String patientDetailPage(int patient_id, Model model){
        model.addAttribute("patient_id", patient_id);
        return "patientDetail";
    }

    @RequestMapping(value = "/bindCard")//病人绑定身份证和医保卡
    public String bindCard(int patient_id, String patient_idcard , String patient_medicard, Model model){
        return patientService.bindCard(patient_id, patient_idcard, patient_medicard, model);
    }

    @RequestMapping(value = "/deletePatientById")//根据病人id删除病人信息
    public String deletePatientById(int patient_id,Model model){
        bindService.deleteBindByPatientId(patient_id, model);  //同时删除病人相关的绑定关系
        return patientService.deletePatientById(patient_id,model);
    }

    @RequestMapping(value = "/listAllPatient")
    public String listAllPatient(Model model){
        return patientService.listAllPatient(model);
    }

    @RequestMapping(value = "/getPatientById")//根据病人id查询病人信息
    public String getPatientById(int patient_id,Model model){
        return patientService.getPatientById(patient_id,model);
    }

    @RequestMapping(value = "/getPatientsCount")//查询病人总数量
    public String getPatientsCount(Model model){
        return patientService.getPatientsCount(model);
    }

    @RequestMapping(value = "/getPatientListByCondition")//根据多个tag筛选病人
    public String getPatientListByCondition(String tagList, Model model){
        List<String> list = Arrays.asList(tagList.split(","));
        return patientService.getPatientListByCondition(list, model);
    }

}